<?php

class HeaderWidget extends CWidget {

    public function run() {
	$top_links = $this->__get_pages();
	$login_register_menu = $this->__get_login_register_menu();
	$this->render('header_widget_view', array('top_links' => $top_links,'login_register_menu'=>$login_register_menu));
    }

    protected function __get_pages() {
	return Menu::get_menu_top_oop_return_html(0);
    }

    protected function __get_login_register_menu() {
	return  $this->widget('zii.widgets.CMenu', array(
	    'htmlOptions' => array('class' => 'register_login_menu'),
	    'items' => array(
		//users
		array(
		    'label' => 'блокнот',
		    'url' => array('/users/logout'),
		    'linkOptions' => array('class' => 'register'),
		    'visible' => Yii::app()->user->checkAccess(Users::ROLE_USER)
		),
		array(
		    'label' => 'Вихід',
		    'url' => array('/users/logout'),
    		    'linkOptions' => array('class' => 'login'),
		    'visible' => Yii::app()->user->checkAccess(Users::ROLE_USER)
		),
		//admin
		array(
		    'label' => 'Адмінка',
		    'url' => array('/admin'),
		    'linkOptions' => array('class' => 'register'),
		    //'itemOptions' => array('class'=> 'register'),
		    'visible' => Yii::app()->user->checkAccess(Users::ROLE_MODER)
		),
		array(
		    'label' => 'Вихід',
		    'url' => array('/users/logout'),
		    'linkOptions' => array('class' => 'login'),
		    //'itemOptions' => array('class'=> 'login'),
		    'visible' => Yii::app()->user->checkAccess(Users::ROLE_MODER)
		),
		// гість
		array(
		    'label' => 'Регістрація',
		    'url' => array('/users/register'),
		    'linkOptions' => array('class' => 'register'),
		    'visible' => Yii::app()->user->isGuest
		),
		array(
		    'label' => 'Вхід',
		    'url' => array('/users/login'),
		    'linkOptions' => array('class' => 'login'),
		    'visible' => Yii::app()->user->isGuest
		),
	    ),
	),TRUE);
    }

}

?>